////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxfd4xhwutils.h
/// @brief Translation utility class
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef CAMXFD4XHWUTILS_H
#define CAMXFD4XHWUTILS_H

#include "camxfdutils.h"

CAMX_NAMESPACE_BEGIN

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Class that implements the FD utility functions for FD core ver 4.0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class FD4xHwUtils
{
public:
    static const UINT FDHWMajorVersion4 = 4;      ///< Indicating FD HW v4.x
    static const UINT FDHWMajorVersion5 = 5;      ///< Indicating FD HW v5.x
    static const UINT FDHWFPSetOffBit   = 0x100;  ///< Bit to set to disable HW FP in v5 hw

    /// FD HW input dimensions
    static const UINT FDVGAWidth        = 640; ///< VGA width
    static const UINT FDVGAHeight       = 480; ///< VGA height
    static const UINT FDQVGAWidth       = 320; ///< QVGA width
    static const UINT FDQVGAHeight      = 240; ///< QVGA height
    static const UINT FDWVGAPlusWidth   = 854; ///< WVGA+ width
    static const UINT FDWVGAPlusHeight  = 480; ///< WVGA+ height
    static const UINT FDWQVGAPlusWidth  = 427; ///< QWVGA+ width
    static const UINT FDWQVGAPlusHeight = 240; ///< QWVGA+ height

    /// FD HW input images
    static const UINT FDInputImageQVGA      = 0; ///< Input image QVGA
    static const UINT FDInputImageVGA       = 1; ///< Input image VGA
    static const UINT FDInputImageWQVGAPlus = 2; ///< Input image WQVGA+
    static const UINT FDInputImageWVGAPlus  = 3; ///< Input image WVGA+

    static const UINT FDPyramidBufferSizeVGA       = 218496; ///< Pyramid/Work buffer size for 640x480 input image
    static const UINT FDPyramidBufferSizeQVGA      = 55680;  ///< Pyramid/Work buffer size for 320x240 input image
    static const UINT FDPyramidBufferSizeWQVGAPlus = 74176;  ///< Pyramid/Work buffer size for 427x240 input image
    static const UINT FDPyramidBufferSizeWVGAPlus  = 290240; ///< Pyramid/Work buffer size for 854x480 input image

    /// different pose angles returned by HW FD
    static const UINT FDHwPoseFront         = 1;    ///< pose front
    static const UINT FDHwPoseRightDiagonal = 2;    ///< pose right diagonal
    static const UINT FDHwPoseRight         = 3;    ///< pose right
    static const UINT FDHwPoseLeftDiagonal  = 4;    ///< pose left diagonal
    static const UINT FDHwPoseLeft          = 5;    ///< pose left

    /// different detection angles for HW FD
    static const UINT FDHwUpwardDirection45     = 0;    ///< direction 0 degrees +/- 45 degrees
    static const UINT FDHwRightDirection45      = 1;    ///< direction 90 degrees +/- 45 degrees
    static const UINT FDHwLeftDirection45       = 2;    ///< direction 270 degrees +/- 45 degrees
    static const UINT FDHwDownwardDirection45   = 3;    ///< direction 180 degrees +/- 45 degrees
    static const UINT FDHwUpwardDirection135    = 4;    ///< direction 0 degrees +/- 135 degrees
    static const UINT FDHwRightDirection135     = 5;    ///< direction 90 degrees +/- 135 degrees
    static const UINT FDHwLeftDirection135      = 6;    ///< direction 270 degrees +/- 135 degrees
    static const UINT FDHwDownwardDirection135  = 7;    ///< direction 180 degrees +/- 135 degrees
    static const UINT FDHwDirectionAll          = 8;    ///< direction 180 degrees +/- 135 degrees

    /// FD minimum face sizes in pixels
    static const UINT FDMinFacePixels0 = 20; ///< minimum face size in pixels 20
    static const UINT FDMinFacePixels1 = 25; ///< minimum face size in pixels 25
    static const UINT FDMinFacePixels2 = 32; ///< minimum face size in pixels 32
    static const UINT FDMinFacePixels3 = 40; ///< minimum face size in pixels 40

    /// FD minimum face size register values mapping to min size in pixels
    static const UINT FDMinFaceSize0 = 0; ///< minimum face size register value 0
    static const UINT FDMinFaceSize1 = 1; ///< minimum face size register value 1
    static const UINT FDMinFaceSize2 = 2; ///< minimum face size register value 2
    static const UINT FDMinFaceSize3 = 3; ///< minimum face size register value 3

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// GetPoseAngleFromRegValue
    ///
    /// @brief  convert results from HW raw format to SW understandable pose
    ///
    /// @param  poseRegValue   FD HW pose
    ///
    /// @return INT32 SW pose value
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    static INT32 GetPoseAngleFromRegValue(
        UINT32 poseRegValue);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// CalculatePyramidBufferSize
    ///
    /// @brief  update the pyramid/work buffer needed for HW FD
    ///
    /// @param  width   HW FD processing frame width
    /// @param  height  HW FD processing frame height
    /// @param  pSize   pointer to the pyramid size
    ///
    /// @return CamxResult Success or fail
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    static CamxResult CalculatePyramidBufferSize(
        UINT32  width,
        UINT32  height,
        UINT32* pSize);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// UpdateFDHwCondValue
    ///
    /// @brief  update the COND HW register based on FD min face size and direction
    ///
    /// @param  hwMajorVersion       FD Hw major version
    /// @param  enableHwFP           Whether to enable False Positive filter in Hw
    /// @param  minFaceSize          Minimum face size
    /// @param  referenceOrientation Reference device orientation
    /// @param  angle                Angle range
    /// @param  pReg                 pointer to the register
    ///
    /// @return CamxResult Success or fail
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    static CamxResult UpdateFDHwCondValue(
        UINT32          hwMajorVersion,
        BOOL            enableHwFP,
        UINT32          minFaceSize,
        INT32           referenceOrientation,
        FDSearchAngle   angle,
        UINT32*         pReg);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// UpdateFDHwImageValue
    ///
    /// @brief  update image register based on dimension
    ///
    /// @param  width   HW FD processing frame width
    /// @param  height  HW FD processing frame height
    /// @param  pReg    pointer to the register
    ///
    /// @return CamxResult Success or fail
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    static CamxResult UpdateFDHwImageValue(
        UINT32  width,
        UINT32  height,
        UINT32* pReg);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// FD4xHwUtils
    ///
    /// @brief Default constructor
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    FD4xHwUtils() = default;
private:
    FD4xHwUtils(const FD4xHwUtils&) = delete;
    FD4xHwUtils& operator=(const FD4xHwUtils&) = delete;
};

CAMX_NAMESPACE_END

#endif // CAMXFD4XHWUTILS_H
